﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vit.Web.Data
{
    public class PageOfList<T> : List<T>, IPageOfList<T>
    {
        public PageOfList(IQueryable<T> query, int pageIndex, int pageSize)
        {
            int totalItemCount = query.Count();
            if (pageIndex < 1)
                pageIndex = 1;
            query = query.Skip((pageIndex - 1) * pageSize).Take(pageSize);
            AddRange(query.ToList());

            PagingInfo = new PagingInfo(pageIndex, pageSize, totalItemCount);
        }

        #region IPageOfList<T> Members

        public PagingInfo PagingInfo { get; private set; }

        #endregion
    }
}
